#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time   : 2021/6/27 23:58
# @Author : cjw

from web_wework.page.base_page import BasePage
from web_wework.setting import ELEMENT_YML
from web_wework.util.file_operator import YmlOperator


class AddDepartmentPage(BasePage):
	"""添加部门页面"""

	# 添加定位元素到locators
	BasePage.locators.update(YmlOperator(ELEMENT_YML['adp']).data)

	def add_department(self, dp_name):
		"""
		添加部门
		:param dp_name: 部门名称
		:return:
		"""
		from web_wework.page.contact_page import ContactPage

		self.department_name.send_keys(dp_name)
		self.select_part.click()
		self.select_part_name.click()
		self.btn_submit.click()
		return ContactPage(self.driver)

	def add_department_fail(self, dp_name, is_select_part: bool = True):
		"""
		添加部门失败
		:param dp_name: 部门名称
		:param is_select_part: 部门名称
		:return:返回失败信息
		"""
		self.department_name.send_keys(dp_name)
		self.select_part.click()
		if is_select_part:
			self.select_part_name.click()
		self.btn_submit.click()
		tip_text = self.find(self.locators['tips_txt']).text
		print(f'错误提示信息：{tip_text}')
		return tip_text
